package com.ricecoder.spring01.service;

import com.ricecoder.spring01.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

//该注解属于component，对应到原来的Dao持久化层
@Repository
public class UserService implements UserDao {

//    自动注入Jdbc模板
    @Autowired
    private JdbcTemplate jdbcTemplate;

//    查询获取所有用户信息
    @Override
    public List<Map<String, Object>> allUsers() {
        List<Map<String, Object>> list =  jdbcTemplate.queryForList("select * from user");
        return list;
    }

//  根据用户姓名来获取其信息
    @Override
    public Map<String, Object> getUserByUserName(String username) {
        Map<String, Object> user =  jdbcTemplate.queryForMap("select * from user where username=?",username);
        return user;
    }

}
